package com.smh.a02MapDemo2;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Test {
    public static void main(String[] args) {

        Map<Student,String> map = new HashMap<>();

        Student student1 = new Student("zhangsan",12,"nan");
        Student student2 = new Student("lisi",14,"nan");
        Student student3 = new Student("wangwu",26,"nan");
        Student student4 = new Student("zhangsan",12,"nan");

        map.put(student1,"hebei");
        map.put(student2,"beijing");
        map.put(student3,"tianjin");
        map.put(student4,"neimenggu");
        System.out.println(map);
        System.out.println("-------------------");
        map.forEach((s,jiguan)->{
            System.out.println(s.getName()+","+s.getAge()+","+s.getGender()+","+jiguan);
        });
        System.out.println("-------------------");
        Set<Student> students = map.keySet();
        for (Student student : students) {
            System.out.println(student+map.get(student));
        }
        System.out.println("-------------------");
        students.forEach(student -> {
            System.out.println(student+map.get(student));
        });
        System.out.println("-------------------");
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()){
            Student student = iterator.next();
            System.out.println(student+map.get(student));
        }
        System.out.println("-------------------");
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            System.out.println(entry.getKey()+entry.getValue());
        }


    }
}
